<?php
namespace Admin\Model;

use Think\Model;

class RoleModel extends Model{
    protected $patchValidate = true;
    protected $_validate = array(
        array('role_name','require','角色名不能为空！',self::MUST_VALIDATE),
        array('role_name','checkRoleUnique_add','该角色已经存在！',self::MUST_VALIDATE,'callback','add'),
        array('role_name','checkRoleUnique','该角色已经存在！',self::MUST_VALIDATE,'callback','edit'),
        array('eName','require','别名不能为空！',self::MUST_VALIDATE),
    );
    protected function checkRoleUnique_add($param){
        $where="role_name='%s'";
        $num=M("Role")->where($where,$param)->count();
        if($num){
             return false;
       }
    }
    protected function checkRoleUnique($param){
        $where="role_name='%s' AND id !='%d'";
        $num=M("Role")->where($where,$param,$this->id)->count();
        if($num){
            return false;
        }
    }

}

?>